package com.neu.cloudFactory.DAO;

import com.neu.cloudFactory.PO.EquipMsg;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface EquipMsgDAO extends JpaRepository<EquipMsg,Integer> {
    //带有CRUD接口

    //查找某设备类型下的设备
    List<EquipMsg> findByTypeId(int id);
    //改变设备运行状态
    @Modifying
    @Query(value = "update e_message set e_m_state = :curState where e_m_id = :curId", nativeQuery = true)
    void modifyRunState(@Param("curState") String curState, @Param("curId") int curId);

    //改变设备租用状态
    @Modifying
    @Query(value = "update e_message set e_m_rentState = :curState where e_m_id = :curId", nativeQuery = true)
    void modifyRentState(@Param("curState") String curState, @Param("curId") int curId);

    //按照租用状态查询设备
    @Query(value = "select * from e_message where e_m_rentState = :state and e_m_source = :source", nativeQuery = true)
    List<EquipMsg> findByRentState(@Param("state") String state,@Param("source") String source);

    //改变设备所属工厂
    @Modifying
    @Query(value = "update e_message set f_id = :newId where e_m_id = :equipId", nativeQuery = true)
    void modifyFactory(@Param("newId") int newId,@Param("equipId") int equipId);

    List<EquipMsg> findByName(String name);

}
